<template>
	<view>
		<uni-section title="科目" type="line">
			<uni-data-select
				v-model="item.subjectId"
				:localdata="range"
				@change="change">
			</uni-data-select>
		</uni-section>
		<uni-section title="事件标题" type="line">
			<uni-easyinput v-model="item.title" placeholder="请输入事件标题" />
		</uni-section>
		<uni-section title="事件内容" type="line">
			<webEdit v-model="item.content" ids="content" :modelValue="item.content" ></webEdit>
		</uni-section>
		<uni-section title="备注" type="line">
			<uni-card :is-shadow="true" is-full>
				<textarea  :value="item.describes"/>
			</uni-card>
		</uni-section>
			<uni-card :is-shadow="true" is-full>
				<button type="primary" @click="submit('valiForm')">确认记录</button>
			</uni-card>
	</view>	
</template>

<script>
import config from "@/config.js";
import { listSubject} from "@/api/plan/subject";
import { updateContent,getContent,addContent} from "@/api/plan/content";
export default {
	data() {
		return {
			item: {
                id: null,
                subjectId: null,
                title: null,
                content: null,
                studyStatus: '1',
                markStatus: null,
                isQueue: null,
                createDate: null,
                describes: null
            },
			range: [],
		}
	},
	onLoad(option) {
		this.getSubjectList();
	},	
	methods: {
		/** 查询科目列表  新增今日学习内容时使用 */
		getSubjectList() {
			let allSubject = {};
			listSubject(allSubject).then(response => {
				let List = response.rows;
				this.range = [];
				for (let index = 0; index < List.length; index++) {
					const element = List[index];
					let obj ={
						value:element.id,
						text:element.pName,
					}
					this.range.push(obj);
				}
			});
		},
		change(e) {
		  console.log("e:", e);
		},
		submit() {			
			let target = config.baseUrl;
			let regex = new RegExp(target, 'g');
			this.item.content = this.item.content.replace(regex, '/dev-api');
			this.item.content = this.item.content.replace(/style="width:100%;height:auto;display:block" /g, '');
			
			addContent(this.item).then(response => {
				uni.showToast({
					title: `添加成功`
				})
				setTimeout(function(){
					uni.navigateBack({
						delta: 1, // 返回层数，2则上上页
						success() {
							uni.$emit('refreshTip',{msg:'Tip'})
						}
					})
				},2000)
			});
		},
	}
}
</script>

<style>
	.example {
		padding: 15px;
		background-color: #fff;
	}
	.content{
		.uni-section-content{
			padding: 0 20px;
		}
	}
</style>